﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace WinNMPForms
{
    internal class Mysql
    {
        private string serverName;
        private bool isRun = false;
        private bool isExits = false;
        public bool IsRun { get => isRun; set => isRun = value; }
        public bool IsExits { get => isExits; set => isExits = value; }
        public string ServerName { get => serverName; set => serverName = value; }

        public Mysql()
        {
            serverName = ConfigurationManager.AppSettings.Get("mysql_servername");
            if (!string.IsNullOrEmpty(serverName))
            {
                try
                {
                    ServiceController service = new ServiceController(serverName);

                    isExits = true;

                    if (service.Status.Equals(ServiceControllerStatus.Running))
                    {
                        isRun = true;
                        Console.WriteLine("Starting the mysql service...");
                    }
                    service.Close();
                }
                catch (Exception e)
                {
                    isExits = false;
                    Console.WriteLine("{0}: {1}", e.GetType().Name, e.Message);
                }
            }
        }
    }
}
